package l.l.w.leetcode.BinaryNumberWithAlternatingBits;

/**
 * Created by llw on 2017/10/15.
 */
public class BinaryNumberWithAlternatingBits {

    public boolean hasAlternatingBits(int n) {
        if( (n &1)==0){
            return ~(n ^ n>>1)==0;
        }else{
            return  ~(n ^ n<<1)==0;
        }
    }

    public static void main(String[] args) {
        int n = 5;
        boolean result = new BinaryNumberWithAlternatingBits().hasAlternatingBits(5);
        System.out.println(result);
    }
}
